package code1_100.code21_30;

/**
 * @author 韩迪
 * @date 2022/03/28 20:10
 **/
public class Code27 {

    public int removeElement(int[] nums, int val) {
        int len = nums.length;
        for (int i = nums.length-1; i >=0 ; i--) {
            if (nums[i] == val) {
                move(nums,i);
                len--;
            }
        }
        return len;
    }

    public void swap(int[] arr,int a,int b){
        int t = arr[a];
        arr[a] = arr[b];
        arr[b] = t;
    }

    public void move(int[] arr,int a){
        for (int i = a; i < arr.length-1; i++) {
            swap(arr,i,i+1);
        }
    }
}
